package cn.hrlly.tao2shou.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.io.File;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.presenter.SubmitApplicationPresenter;
import cn.hrlly.tao2shou.presenter.SubmitApplicationPresenterImpl;
import cn.hrlly.tao2shou.view.base.BaseActivity;
import cn.hrlly.tao2shou.view.view_interface.SubmitApplicationView;

public class SubmitApplicationActivity extends Activity implements SubmitApplicationView {

    @Bind(R.id.etExpectedPrice)
    EditText etExpectedPrice;
    @Bind(R.id.etTradeTime)
    EditText etTradeTime;
    @Bind(R.id.etTradeLocation)
    EditText etTradeLocation;
    @Bind(R.id.viewPager)
    ViewPager viewPager;
    @Bind(R.id.etBarterName)
    EditText etBarterName;
    @Bind(R.id.layoutBarterName)
    LinearLayout layoutBarterName;
    @Bind(R.id.etBarterDescription)
    EditText etBarterDescription;
    @Bind(R.id.layoutBarterDescription)
    LinearLayout layoutBarterDescription;
    @Bind(R.id.btnSubmit)
    Button btnSubmit;
    private Intent intent;
    private SubmitApplicationPresenter submitApplicationPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_submit_application);
        //控件绑定
        ButterKnife.bind(this);
        //初始化
        intent = getIntent();
        submitApplicationPresenter = new SubmitApplicationPresenterImpl(this);

        if(intent.getIntExtra(Config.key_trade_method,0)==0){
            viewPager.setVisibility(View.VISIBLE);
            layoutBarterName.setVisibility(View.VISIBLE);
            layoutBarterDescription.setVisibility(View.VISIBLE);
        }

    }

    //btnSubmit点击事件
    @OnClick(R.id.btnSubmit)
    public void submit(){
        if(!etExpectedPrice.getText().toString().equals("")&&!etTradeTime.getText().toString().equals("")&&!etTradeLocation.getText().toString().equals(""))
            submitApplicationPresenter.submitApplicationPresenter();
        else
            showMessage(R.string.fill_incomplete);
    }

    //以下是对activity的操作
    @Override
    public String getReleaseId() {
        return intent.getStringExtra(Config.key_release_id);
    }

    @Override
    public double getExpectedPrice() {
        return Double.parseDouble(etExpectedPrice.getText().toString());
    }

    @Override
    public String getTradeTime() {
        return etTradeTime.getText().toString();
    }

    @Override
    public String getTradeLocation() {
        return etTradeLocation.getText().toString();
    }

    @Override
    public String getPublisherId() {
        return intent.getStringExtra(Config.key_seller_id);
    }

    @Override
    public String getBarterName() {
        return etBarterName.getText().toString();
    }

    @Override
    public File[] getBarterPhotos() {
        return new File[0];
    }

    @Override
    public String getBarterDescription() {
        return etBarterDescription.getText().toString();
    }

    @Override
    public void showMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showMessage(int message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void finishActivity() {
        finish();
    }
}
